var util = require('../../utils/util.js');
var app=getApp()
Page({
  data: {
       name:'',
       price:'',
       account:'',
       pwd:'',
       info:'',
       userId:'',
       time:'',
       type:''
  },
  name:function(e){
    this.setData({
      name:e.detail.value
    })
  },
  price:function(e){
    this.setData({
      price:e.detail.value
    })
  },
  account:function(e){
    this.setData({
      account:e.detail.value
    })
  },
  pwd:function(e){
    this.setData({
      pwd:e.detail.value
    })
  },
  info:function(e){
    this.setData({
      info:e.detail.value
    })
  },
  type:function(e){
    this.setData({
      type:e.detail.value
    })
  },
  submit:function(e){
    var i;
    var that=this;
    that.setData({
      userId:app.globalData.userInfoList.userId
      })
    // console.log(that.data.userId)

    for(i=1;i<app.globalData.gameImage.length;i++){
      if(that.data.type===app.globalData.gameImage[i].name) break;
    }
    // console.log(i)
    // console.log(that.data.type)
    // console.log(app.globalData.gameImage[0].name)
    if(i<13){
    wx.request({
        url:app.globalData.url+'goodAddAction',
        data:{
         userId:that.data.userId,
         gameId:i,
         goodName:that.data.name,
         goodPrice:that.data.price,
         goodAccount:that.data.account,
         goodPwd:that.data.pwd,
         goodIntro:that.data.info,
         goodTime:util.formatTime(new Date()),
         goodPicture1:'',
         goodPicture2:'',
         goodPicture3:'',
       },
       success(e){
       wx.showToast({
         title: '发布成功',
         icon:'none'
       })
      //  wx.reLaunch({
      //   url: '',
      // })
    }
})}else{
  wx.showToast({
    title: '发布失败',
    icon:'none'
  })}
},
 })